<?php

namespace App\Admin\Validate\Base;

use App\Common\Enums\Base\AdministratorsEnumStatus;
use App\Common\Model\Base\Administrators;
use App\Common\Validate\AbstractValidate;

/**
 * Class AdministratorsValidate
 */
class AdministratorsValidate extends AbstractValidate
{

    public function allRules(): array
    {
        return [
            'id'          => ['number', 'require'],
            'name|用户名'   => ['require'],
            'account|账号'  => ['require', 'string', 'unique' => implode(',', [Administrators::class , 'administrators^account', $this->input('id')])],
            'password|密码' => ['require', 'string', 'length' => '6,20'],
            'role_ids|角色' => ['array'],
            'status|状态'   => ['require', 'integer', 'in' => implode(',', AdministratorsEnumStatus::values())],
        ];
    }

    public function allMessages(): array
    {
        return [];
    }

    public function sceneStore(): static
    {
        return $this->remove('id', 'require');
    }

    public function sceneUpdate(): static
    {
        return $this->remove('password', 'require');
    }

    public function sceneDestroy(): static
    {
        return $this->rule(['ids|要删除的数据' => 'require|array'])->only(['ids']);
    }
}